package com.tuozixuan.thymeleaf.demo;


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.StringTemplateResolver;

public class ThymeleafTextDemo {

	public static void main(String[] args) {
		
		StringTemplateResolver templateResolver = new StringTemplateResolver();
		templateResolver.setTemplateMode(TemplateMode.TEXT);
		
		TemplateEngine templateEngine = new TemplateEngine();
		templateEngine.setTemplateResolver(templateResolver);
		
		Context context = new Context();
//		context.setVariable("name", "lisi");
		
		Map<String, Object> map = new HashMap<>();
		map.put("name", "lisi");
		map.put("items", Arrays.asList("one", "two", "three"));
		context.setVariables(map);
		
		String textContent = "my name is [[${name}]]"
				+ "	[# th:each=\"item : ${items}\"]\r\n"
				+ "  		- [(${item})]\r\n"
				+ "	[/]";
		
		// [[]]对应th:text  [()]对应th:utext
		//String result = templateEngine.process("my name is [(${name})]", context);
		String result = templateEngine.process(textContent, context);
		System.out.println(result);
	}

}
